package com.ruoyi.web.controller.doctor;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.domain.entity.SysDept;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.doctor.domain.DoctorPatient;
import com.ruoyi.doctor.service.impl.DoctorRegisListServiceImpl;
import com.ruoyi.system.domain.SysRegister;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

@RestController
@RequestMapping("/xl/regisList")
public class DoctorRegisListController extends BaseController {

    @Autowired
    DoctorRegisListServiceImpl service;

    private String deptName;
    private String registerName;
    private DoctorPatient doctorPatient;

    //查询全部
    @PreAuthorize("@ss.hasPermi('system:check:list')")
    @GetMapping("/list")
    public TableDataInfo list(DoctorPatient sysPatient, String deptName, String registerName)
    {
        this.deptName = deptName;
        this.registerName = registerName;
        this.doctorPatient = sysPatient;
        System.out.println("我是check");
        startPage();
        List<DoctorPatient> sysPatients = service.queryAll(sysPatient,deptName,registerName);
        //System.out.println(sysChecks);
        return getDataTable(sysPatients);
    }


    //收费状态
    @GetMapping("/updateStatus")
    public int updateStatus(int patientId,int patientStatus)
    {
        if(patientStatus == 0){
            //收费
            return service.update0(patientId);
        }
        if(patientStatus == 1){
            return service.update1(patientId);
        }
        return -1;
    }

    //查询所有部门
    @GetMapping("/listDepts")
    public List<SysDept> listDept(){
        return service.queryDept();
    }

    //查询所有挂号类型
    @GetMapping("/listRegistrs")
    public List<SysRegister> listRegistrs(){
        return service.queryRegis();
    }


    @PreAuthorize("@ss.hasPermi('monitor:operlog:remove')")
    @Log(title = "通知公告", businessType = BusinessType.DELETE)
    @DeleteMapping("/{patientId}")
    public AjaxResult remove(@PathVariable Long[] patientId) {
        return toAjax(service.deletePatientByIds(patientId));
    }




    @Log(title = "操作日志", businessType = BusinessType.EXPORT)
    @PreAuthorize("@ss.hasPermi('registers:registList:export')")
    @PostMapping("/export")
    public void export(HttpServletResponse response)
    {
        List<DoctorPatient> registLists = service.queryAll(doctorPatient,this.deptName,this.registerName);
        ExcelUtil<DoctorPatient> util = new ExcelUtil<>(DoctorPatient.class);
        util.exportExcel(response, registLists, "挂号列表");
    }


}
